<template>
  <div class="cpu-container">
    <p class="title">设备CPU占比</p>
    <div class="cpu-chart-div">
      <div class="chart-header">
        <span>设备名</span>
        <div>
          <span v-for="item in header" :key="item">{{ item }}</span>
        </div>
      </div>
      <ul>
        <li class="strip" v-for="(item, index) in data" :key="index">
          <span>{{ item.text }}</span>
          <p :style="{ width: item.value }"></p>
          <i :style="{ left: item.value }">{{ item.value }}</i>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import { cpuAndMem } from '@/api/homePage'

export default {
  name: 'DeviceCPU',
  data() {
    return {
      header: ['0%', '15%', '30%', '45%', '60%'],
      data: []
    }
  },
  mounted() {
    this.doQuery()
  },
  methods: {
    async doQuery() {
      const {
        data: { data }
      } = await cpuAndMem()

      this.data = data.cpuList.map(item => {
        return {
          usedCpu: item.usedCpu,
          value: item.usedCpu + '%',
          text: item.name
        }
      })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss">
* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}
.cpu-container {
  position: absolute;
  width: 320px;
  height: 460px;
  top: 100px;
  left: 1573px;
  background-size: 100%;
  background-image: url(../../assets/platform/T.Right.png);

  .title {
    text-align: center;
    color: #00c2ff;
    font-size: 16px;
    height: 58px;
    line-height: 58px;
    background: linear-gradient(
      135deg,
      rgba(42, 163, 255, 0.20000000298023224) 0%,
      rgba(43, 112, 156, 0.00009999999747378752) 100%
    );
    border-bottom: 2px solid;
    border-image: radial-gradient(
        circle,
        rgba(42.5000012665987, 162.608702480793, 255, 1),
        rgba(
          28.000000230968,
          109.00000110268593,
          171.00000500679016,
          0.4000000059604645
        ),
        rgba(
          43.00000123679638,
          112.000000923872,
          156.00000590085983,
          0.10000000149011612
        )
      )
      2 2;
  }
}
.chart-header {
  width: 100%;
  position: relative;
  padding-bottom: 24px;
  > span {
    color: #fff;
    width: 100px;
  }
  > div {
    color: rgba(255, 255, 255, 0.8);
    position: absolute;
    left: 83px;
    display: flex;
    top: 0;
    width: calc(100% - 83px);
    justify-content: space-between;
    span {
      position: relative;
      display: inline-block;
      width: 34px;
      text-align: center;
    }
    span:after {
      position: absolute;
      content: '';
      width: 1px;
      height: 318px;
      background: rgba(92, 215, 253, 0.3);
      display: inline-block;
      top: 42px;
      right: 17px;
    }
  }
}
.cpu-chart-div {
  width: 100%;
  height: 400px;
  padding: 24px 12px 12px;
  .strip {
    position: relative;
    list-style: none;
    margin-bottom: 32px;
    span {
      width: 100px;
      color: #fff;
      font-size: 14px;
    }
    p {
      position: absolute;
      left: 100px;
      height: 16px;
      display: inline-block;
      background: linear-gradient(
        270deg,
        rgba(122, 210, 255, 0.8) 0%,
        rgba(0, 57, 148, 0.8) 100%
      );
      border-bottom-right-radius: 30px;
      border-top-right-radius: 30px;
    }
    i {
      color: #fff;
      font-style: normal;
      font-size: 14px;
      position: absolute;
      margin-left: 106px;
    }
  }
}
</style>
